import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.*;

import com.jgoodies.forms.layout.*;
//import org.jdesktop.swingx.*;
/*
 * Created by JFormDesigner on Mon Apr 18 21:21:18 CDT 2011
 */



/**
 * @author Becca Emrick
 */
public class EditorGUI extends JFrame {
//	private JButton newButton;
//	private JButton saveButton;
//	private JButton openButton;
//	private JButton playButton;
	
	public EditorGUI() {
		initComponents();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	private void addStraightPart(ActionEvent e) {
		System.out.println("Render Straight Piece");
		GameManager.GM.graphicsEngine.renderDefaultStraightPiece();
	}

	private void addLeftCurve(ActionEvent e) {
		System.out.println("Render Left Curve");
		GameManager.GM.graphicsEngine.renderDefaultLeftCurve();
	}

	private void addRightCurve(ActionEvent e) {
		System.out.println("Render Right Curve");
		GameManager.GM.graphicsEngine.renderDefaultRightCurve();
	}

	private void addCurveUpPart(ActionEvent e) {
		System.out.println("Render Up Curve");
		GameManager.GM.graphicsEngine.renderDefaultUpCurve();
	}

	private void addCurveDownPart(ActionEvent e) {
		System.out.println("Render Down Curve");
		GameManager.GM.graphicsEngine.renderDefaultDownCurve();
	}

	private void saveCoaster(ActionEvent e) {
		System.out.println("Save Coaster");
		GameManager.GM.saveWindow.setVisible(true);
		
	}

	private void openCoaster(ActionEvent e) {
		System.out.println("Open Coaster");
//		ArrayList<String> coasters = GameManager.GM.database.getAllCoasterNames();
		ArrayList<String> coasters = createFakeCoasterList(); //delete me when database is working
//		this.setVisible(false);
		GameManager.GM.openWindow.addCoasterList(coasters);
		GameManager.GM.openWindow.setVisible(true);
		GameManager.GM.openWindow.requestFocus();
	}

	private ArrayList<String> createFakeCoasterList() {
		ArrayList<String> coasters = new ArrayList<String>();
		coasters.add("Clanging Fred");
		coasters.add("Business Casual");
		coasters.add("Awww Hell Naw");
		coasters.add("Grrr! Feeble Air");
		coasters.add("A Chemical Milk");
		coasters.add("Filched Racism");
		return coasters;
	}

	private void playCoaster(ActionEvent e) {
		System.out.println("Watch Coaster Go!");
		GameManager.GM.graphicsEngine.runCoaster();
	}

	private void stopCoaster(ActionEvent e) {
		System.out.println("Stop Coaster Stop!");
		GameManager.GM.graphicsEngine.stopCoaster();
	}

	private void deletePart(ActionEvent e) {
		System.out.println("Delete Part");
		GameManager.GM.graphicsEngine.deletePart();
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - Becca Emrick
		panel1 = new JPanel();
		newButton = new JButton();
		saveButton = new JButton();
		openButton = new JButton();
		deleteButton = new JButton();
		toggleGrid = new JToggleButton();
		playButton = new JButton();
		stopButton = new JButton();
		panel2 = new JPanel();
		straightPartButton = new JButton();
		leftPartButton = new JButton();
		RightPartButton = new JButton();
		curveUpButton = new JButton();
		curveDownButton = new JButton();
		straightChainButton = new JButton();

		//======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(null);

		//======== panel1 ========
		{

			// JFormDesigner evaluation mark
			panel1.setBorder(new javax.swing.border.CompoundBorder(
				new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
					"JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
					javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
					java.awt.Color.red), panel1.getBorder())); panel1.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

			panel1.setLayout(new FlowLayout());

			//---- newButton ----
			newButton.setIcon(new ImageIcon(getClass().getResource("/newRC.png")));
			newButton.setToolTipText("New Coaster");
			panel1.add(newButton);

			//---- saveButton ----
			saveButton.setIcon(new ImageIcon(getClass().getResource("/save_icon1.gif")));
			saveButton.setToolTipText("Save Coaster");
			saveButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					saveCoaster(e);
				}
			});
			panel1.add(saveButton);

			//---- openButton ----
			openButton.setIcon(new ImageIcon(getClass().getResource("/open2.png")));
			openButton.setSelectedIcon(null);
			openButton.setToolTipText("Open Coaster");
			openButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					openCoaster(e);
				}
			});
			panel1.add(openButton);

			//---- deleteButton ----
			deleteButton.setIcon(new ImageIcon(getClass().getResource("/erase.gif")));
			deleteButton.setToolTipText("Delete Track Part");
			deleteButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					deletePart(e);
				}
			});
			panel1.add(deleteButton);

			//---- toggleGrid ----
			toggleGrid.setIcon(new ImageIcon(getClass().getResource("/grid.png")));
			panel1.add(toggleGrid);
			toggleGrid.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					GameManager.GM.glWindow.toggleGrid();
				}
			});

			//---- playButton ----
			playButton.setIcon(new ImageIcon(getClass().getResource("/playButton.png")));
			playButton.setToolTipText("Begin Ride");
			playButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					playCoaster(e);
				}
			});
			panel1.add(playButton);

			//---- stopButton ----
			stopButton.setIcon(new ImageIcon("/export/home/f09/emrickra/eclipse-work/coaster-architect/stop_icon1.png"));
			stopButton.setToolTipText("Stop Ride");
			stopButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					stopCoaster(e);
				}
			});
			panel1.add(stopButton);
		}
		contentPane.add(panel1);
		panel1.setBounds(new Rectangle(new Point(15, 10), panel1.getPreferredSize()));

		//======== panel2 ========
		{
			panel2.setLayout(new GridBagLayout());
			((GridBagLayout)panel2.getLayout()).columnWidths = new int[] {0, 0, 0, 0};
			((GridBagLayout)panel2.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
			((GridBagLayout)panel2.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 1.0E-4};
			((GridBagLayout)panel2.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 1.0E-4};

			//---- straightPartButton ----
			straightPartButton.setText("Straight");
			straightPartButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					addStraightPart(e);
				}
			});
			panel2.add(straightPartButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- leftPartButton ----
			leftPartButton.setText("Left ");
			leftPartButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					addLeftCurve(e);
				}
			});
			panel2.add(leftPartButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- RightPartButton ----
			RightPartButton.setText("Right");
			RightPartButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					addRightCurve(e);
				}
			});
			panel2.add(RightPartButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));

			//---- curveUpButton ----
			curveUpButton.setText("Curve Up");
			curveUpButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					addCurveUpPart(e);
				}
			});
			panel2.add(curveUpButton, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- curveDownButton ----
			curveDownButton.setText("Curve Down");
			curveDownButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					addCurveDownPart(e);
				}
			});
			panel2.add(curveDownButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 5), 0, 0));

			//---- straightChainButton ----
			straightChainButton.setText("Straight Chain");
			panel2.add(straightChainButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(0, 0, 5, 0), 0, 0));
		}
		contentPane.add(panel2);
		panel2.setBounds(new Rectangle(new Point(15, 80), panel2.getPreferredSize()));

		{ // compute preferred size
			Dimension preferredSize = new Dimension();
			for(int i = 0; i < contentPane.getComponentCount(); i++) {
				Rectangle bounds = contentPane.getComponent(i).getBounds();
				preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
				preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
			}
			Insets insets = contentPane.getInsets();
			preferredSize.width += insets.right;
			preferredSize.height += insets.bottom;
			contentPane.setMinimumSize(preferredSize);
			contentPane.setPreferredSize(preferredSize);
		}
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - Becca Emrick
	private JPanel panel1;
	private JButton newButton;
	private JButton saveButton;
	private JButton openButton;
	private JButton deleteButton;
	private JToggleButton toggleGrid;
	private JButton playButton;
	private JButton stopButton;
	private JPanel panel2;
	private JButton straightPartButton;
	private JButton leftPartButton;
	private JButton RightPartButton;
	private JButton curveUpButton;
	private JButton curveDownButton;
	private JButton straightChainButton;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
	
	public static void main(String [] args){
		EditorGUI gui=  new EditorGUI();
		gui.setSize(1000,1000);
		gui.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		gui.setVisible(true);
	}
	}
